#include "mysql/mysql.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <errno.h>
#include <err.h>

#define MYSQL_HOST					"localhost"
#define MYSQL_USER					"root"
#define MYSQL_PASS					"1q2w3e4r"
#define MYSQL_DB					"test2"
#define MYSQL_SOCK					"/var/run/mysqld/mysqld.sock"

MYSQL *conn;
MYSQL_RES *res = NULL;
MYSQL_ROW row;

void mysqlconnect(){

	conn = mysql_init(NULL);

	if (!mysql_real_connect(conn, MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB, 0, MYSQL_SOCK, 0)){

		fprintf(stderr, "%s\n", mysql_error(conn));

	}

}

//sprintf(query, "INSERT INTO click SET domain='%s', ip_addr='%s', time=UNIX_TIMESTAMP(), systime=NOW()", data, client->ip_addr);
void mysqlquery(char query[]){

	if(conn){

		if (mysql_query(conn, query)){

			fprintf(stderr, "%s\n", mysql_error(conn));

		}

	}

	return;

}

void mysql_fetchrow(){
	//res = mysql_store_result(&conn);
	//mysql_free_result(res);
	//res = NULL;
}

void mysqlclose(){
	mysql_close(conn);
}
